const path = require('path')
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
module.exports = {
  productionSourceMap: false,
  devServer: {
    disableHostCheck: true, // 绕过host检测
    compress: true,
    host: '0.0.0.0', // 微信外网调试用
    port: 8088
  },
  configureWebpack: {
    resolve: {
      alias: {
        '@': path.join(__dirname, './src')
      }
    },
    plugins: [
      new VuetifyLoaderPlugin()
    ]
  },
  pages: {
    www: {
      entry: 'src/apps/www/index.js',
      template: 'public/index.html',
      filename: 'index.html',
      chunks: ['chunk-common', 'chunk-www-vendors', 'www']
      // title: 'Index Page'
    },
    // demo: {
    //   entry: 'src/index/index.js',
    //   template: 'public/index.html',
    //   filename: 'demo.html',
    //   chunks: ['chunk-common', 'chunk-demo-vendors', 'demo']
    //   // title: 'Index Page'
    // },
    wx: {
      entry: 'src/apps/wx/wx.js',
      template: 'public/wx.html',
      filename: 'wx.html',
      chunks: ['chunk-common', 'chunk-wx-vendors', 'wx']
    },
    admin: {
      entry: 'src/apps/admin/admin.js',
      template: 'public/admin.html',
      filename: 'admin.html',
      chunks: ['chunk-common', 'chunk-admin-vendors', 'admin']
    },
    shop: {
      entry: 'src/apps/shop/shop.js',
      template: 'public/shop.html',
      filename: 'shop.html',
      chunks: ['chunk-common', 'chunk-shop-vendors', 'shop']
    },
    member: {
      entry: 'src/apps/member/member.js',
      template: 'public/member.html',
      filename: 'member.html',
      chunks: ['chunk-common', 'chunk-member-vendors', 'member']
    }
  },
  chainWebpack: config => {
    const IS_VENDOR = /[\\/]node_modules[\\/]/
    config.optimization.splitChunks({
      cacheGroups: {
        www: {
          name: `chunk-www-vendors`,
          priority: -11,
          chunks: chunk => chunk.name === 'www',
          test: IS_VENDOR,
          enforce: true
        },
        // demo: {
        //   name: `chunk-demo-vendors`,
        //   priority: -11,
        //   chunks: chunk => chunk.name === 'demo',
        //   test: IS_VENDOR,
        //   enforce: true,
        // },
        admin: {
          name: `chunk-admin-vendors`,
          priority: -11,
          chunks: chunk => chunk.name === 'admin',
          test: IS_VENDOR,
          enforce: true
        },
        wx: {
          name: `chunk-wx-vendors`,
          priority: -11,
          chunks: chunk => chunk.name === 'wx',
          test: IS_VENDOR,
          enforce: true
        },
        common: {
          name: 'chunk-common',
          priority: -20,
          chunks: 'initial',
          minChunks: 2,
          reuseExistingChunk: true,
          enforce: true
        }
      }
    })
    // config
    // .plugin('webpack-bundle-analyzer')
    // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  }
}
